//1. 导入服务器模块
const express = require('express');
//2. 创建web服务器
const app = express();
const cors = require('cors');
var cookieParser = require('cookie-parser')
    //4. 监听客户的get和post请求 并且相应内容
app.use(cookieParser())
app.get('/user', (req, res) => {
    // res.cookie('名字', '值',{参数设置});

    if (req.cookies.name) {
        res.send({ name: 'zks', age: 15, gender: '男' });
        console.log('Cookies: ', req.cookies.name)
    } else {
        res.cookie('name', 'zzks', {
            path: 'user',
            maxAge: 10000,
            expires: new Date().valueOf() * 100,
            Size: 2000
        }); //毫秒单位
        res.send('你好')
    }


})


//3.启动服务器
app.listen(5050, () => {
    console.log('express server running at http://127.0.0.1:5050');
})